<template>
	<view>
		<view style="margin-top: 10rpx;background-color:#fee2cc;margin-left: -30rpx;margin-right: 300rpx;height: 60rpx;width: 250rpx;">
					  <text style="padding-left: 70rpx;padding-top: 10rpx;position: absolute;">实名认证</text>
					  </view>
			  <u-form>
		  			<u-form-item label="真实姓名" label-width="140rpx" style="width: 88%;margin: 0 auto;"  >
		  				<u-input v-model="form.name" shape="circle" />
		  			</u-form-item>
		  			<u-form-item label="身份证号" label-width="140rpx" style="width: 88%;margin: 0 auto;">
		  				<u-input v-model="form.ID" shape="circle"/>
		  			</u-form-item>
                    <u-form-item label="认证状态" label-width="140rpx" style="width: 88%;margin: 0 auto;">
                    	<text style="font-size: 35rpx;font-weight: bold;">{{form.state}}</text>
                    </u-form-item>
			 </u-form>
			 <u-button style="margin-top: 30rpx;background-color:#fee2cc;width: 90%;border-radius: 30rpx;" @click="arrestation">认证</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
				form:{
					name:"",
					ID:"",
					state:""
				},
				userinfo:{}
				
			};
		},
		onLoad(){
			this.$H.get("/user/userInfo").then(res=>{
				this.userinfo=res.result
				if(res.result.realarrest==0){this.form.state="未认证"}
				if(res.result.realarrest==1){this.form.state="已认证"}
			})
			
			
		},
		methods:{
			arrestation(){
				 const regPsidno = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[X])$)$/
				if(this.form.state=="已认证")
				{
					this.$u.toast('已认证');
					return;
				}
				if(!this.form.name){
					this.$u.toast('请填写姓名');
					return;
				}
				if(!this.form.ID){
					this.$u.toast('请填写身份证号');
					 
							
					return;
				}
				if(!regPsidno.test(this.form.ID)){
					this.$u.toast('请输入正确的身份证号');
					 	
					return;
				}
				
				this.$H.post("/user/IDArrestation?name="+this.form.name+"&ID="+this.form.ID).then(res=>{
					if(res.result.respCode=="0000"){
					uni.showToast({
						title:"认证成功",
						icon:"success"
					})
					
					let user={
						id: this.userinfo.id,
						realarrest:1
					}
					this.$H.post("/user/update",user).then(res=>{
						if(res.code==200){
						this.form.state="已认证"
						setTimeout(function () {
						                        uni.reLaunch({
						                        	url:'/pages/mine/index'
						                        })
						                    }, 2000)
											}
						
					})

					}
					
					else{
						this.$u.toast(res.result.respMessage);
					}
				})
			}
		}
	}
</script>

<style lang="less">

</style>
